import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.Image;
public class Character extends Sprite implements Constants
{
	public int m_iSpeed;
	public int m_iBlood;
	public int m_iCharacterX;
	public int m_iCharacterY;
	public int iInMapX;
	public int iInMapY;
	public static Image m_imgCharacter;
	public int[] m_frameSequence;
	public int m_iDir;
	public int iSpr=0;
	public int iDepth;
	public int iID;
	public static int s_iID=0;
	public int m_iUndeadTime = 0;
	public int iCurrentBomb=0;
	public int[] m_abBombkind = { 1200, 1400, 1600, 1800, 2000, 900, -1, 0, 0, 0, 0, 0};
	public Character(Sprite spr){
		super(spr);
		m_iBlood = 4;		
		iInMapX=25;
		iInMapY=15;
		m_iCharacterX =iInMapX*CELL_SIZE;
		iDepth=m_iCharacterY =iInMapY*CELL_SIZE;
		m_iDir = 2;
		m_iSpeed=2;
		s_iID++;
		iID=s_iID;
	}
	public Character(Image img, int w, int h)
	{
		super(new Sprite(img, w, h));				
		m_iBlood = 4;		
		iInMapX=25;
		iInMapY=15;
		m_iCharacterX =iInMapX*CELL_SIZE;
		iDepth=m_iCharacterY =iInMapY*CELL_SIZE;
		m_iDir = 2;
		m_iSpeed=2;
		s_iID++;
		iID=s_iID;
	}
	public Character(Sprite spr, int StartPointX, int StartPointY ){
		super(spr);
		m_iBlood = 4;		
		iInMapX=StartPointX;
		iDepth=iInMapY=StartPointY;
		m_iCharacterX = StartPointX*CELL_SIZE;
		m_iCharacterY = StartPointY*CELL_SIZE;
		m_iDir = 2;
		m_iSpeed = 2;
		s_iID++;
		iID=s_iID;
	}
	
	public Character(int Blood, int x_character, int y_character, Image image, int FrameW, int FrameH , int[] sequence, int dir){
		super(image, FrameW, FrameH);
		m_iBlood = Blood;
		m_iCharacterX = x_character;
		m_iCharacterY = y_character;
		m_imgCharacter = image;
		m_frameSequence = sequence;
		m_iDir = dir;
		s_iID++;
		iID=s_iID;
			
	}
	public Character(Character character){
		super(character);
		m_iBlood = character.m_iBlood;
		m_iCharacterX = character.m_iCharacterX;
		m_iCharacterY = character.m_iCharacterY;
		m_imgCharacter = character.m_imgCharacter;
		m_frameSequence = character.m_frameSequence;
		m_iDir = character.m_iDir;	
		iInMapX= character.iInMapX;	
		iInMapY= character.iInMapY;
		m_iSpeed= character.m_iSpeed;
		iDepth= character.iDepth;
		s_iID++;
		iID=s_iID;
	}
	// COMMON FUNCTION
	public void Update(){
		
	}
	public void Move(){
		
	}
	public boolean CheckCollision(){		
		return true;
	}
	
	public boolean CheckDie()
	{
		if(m_iBlood<=0)
			return true;
			return false;
	}
	
	public int DecreaseBlood(int[][] data)
	{
		if(m_iUndeadTime>0) return 0;
		if(data[iInMapY][iInMapX] > HIT_B && data[iInMapY][iInMapX] <=HIT_A) //>500 && <=700
		{
			if(--m_iBlood >0)
			{
				m_iUndeadTime = 3000;
				return 1;
			}
			else return -1;
		}
		return 0;
	}	
	
	public void PutCharacter(){
		
	}
	public void DrawSprite()
	{
		if((m_iUndeadTime>0) && (m_iUndeadTime%200) >0) 
			{
			m_iUndeadTime -=100;
			return;
			}		
		setPosition(m_iCharacterX-cGame.iViewX-5, m_iCharacterY-cGame.iViewY-8);
		paint(cGame.s_g);
		m_iUndeadTime -=100;
	}
	
	public void DrawHeathBar()
	{
		
		int icRed=255-60*m_iBlood;
		int icGreen=60*m_iBlood;
		if(icRed>255)icRed=255;
		if(icGreen<0) icGreen=0;
		cGame.s_g.setColor(c_blue);
		cGame.s_g.drawRect(m_iCharacterX-cGame.iViewX-11, m_iCharacterY-cGame.iViewY-20, 32,4);		
		cGame.s_g.setColor(icRed, icGreen,0);
		cGame.s_g.fillRect(m_iCharacterX-cGame.iViewX-10, m_iCharacterY-cGame.iViewY-19, 8*m_iBlood-1,3);		
	}	
	
	public boolean CheckNextCellFree(int [][] data, int iDir)
	{
		int x=iInMapX;
		int y=iInMapY;
		if(iDir==D_RIGHT)
			x+=1;
			else if(iDir==D_UP)
			y-=1;
			else if(iDir==D_LEFT)
			x-=1;
			else if(iDir==D_DOWN)
			y+=1;
		if(data[y][x]>=FREE_CELL && data[y][x]<BOMB)
			return true;
		return false;
	}
	public void SetPosition(int x, int y)
	{
		iInMapX=x;
		iInMapY=y;
			m_iCharacterX =iInMapX*CELL_SIZE;
		iDepth=m_iCharacterY =iInMapY*CELL_SIZE;
	}	
	// SUB FUNCTION
	
}
